package com.js.study.datastructs.kmp;

/**
 * @Author JiangSen
 * @DATE 2023/12/26 19:17
 */
public class V1 {
     private Integer[] getNext(String T, Integer[] next){
        int j =1;
        int t =0;
        next[1]=0;
        char[] s = T.toCharArray();
        while(j < s.length){
            if(t ==0 || s[j] == s[t]){
                next[j+1] = t+1;
                ++t;
                ++j;
            }else{
                t = next[t];
            }
        }
        return next;
    }

    public static void main(String[] args) {
        V1 v1 = new V1();
        Integer[] next = new Integer[10];
        String a = "ababaaaba";
        Integer[] next1 = v1.getNext(a, next);
        for (int i = 0; i < next1.length; i++) {
            System.out.print(next1[i]+" ");
        }
    }
}
